package gui.components.objectinfo;

import gui.components.objectinfo.info.orderQueue;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import simulation.Connection;

public class Objectinfo_Info {
        private JPanel top = new JPanel(new BorderLayout());
        private JPanel middle = new JPanel(new BorderLayout());
        private JPanel bottom = new JPanel();
        
        private String lblName;
        private String lblType;
        private int lblHealth;
        private double lblFuel;
        private double lblPositionX;
        private double lblPositionY;
        private double lblSpeed;
        private double lblDirection;
        
        public JPanel createPanelElements(){
                //TODO
                JPanel pnlMain = new JPanel(new GridBagLayout());
                GridBagConstraints c = new GridBagConstraints();
                top.setPreferredSize(new Dimension(335, 200));
                c.gridx = 0;
                c.gridy = 0;
                        //Get values
                        updateObjectInfo();             
                        // Fill top box 'Status' with information
                        top.setBorder(BorderFactory.createTitledBorder("STATUS"));
                                JPanel pnlStatus = new JPanel(new GridLayout(7,1));
                                //name
                                        JLabel lbName = new JLabel("Name");
                                        pnlStatus.add(lbName);
                                        pnlStatus.add(new JLabel(lblName));
                                //type
                                        JLabel lbType = new JLabel("Type");
                                        pnlStatus.add(lbType);
                                        pnlStatus.add(new JLabel(lblType));
                                //health
                                        JLabel lbHealth = new JLabel("Health");
                                        pnlStatus.add(lbHealth);
                                        pnlStatus.add(new JLabel("" + lblHealth));
                                //health
                                        JLabel lbFuel = new JLabel("Fuel");
                                        pnlStatus.add(lbFuel);
                                        pnlStatus.add(new JLabel("" + lblFuel));
                                //position
                                        DecimalFormat df = new DecimalFormat("###.##");
                                        JLabel lbPosition = new JLabel("Position");
                                        pnlStatus.add(lbPosition);
                                        pnlStatus.add(new JLabel("X: " + df.format(lblPositionX) + "  Y: " + df.format(lblPositionY)));
                                //speed
                                        JLabel lbSpeed = new JLabel("Speed");
                                        pnlStatus.add(lbSpeed);
                                        pnlStatus.add(new JLabel(lblSpeed + " km p/h"));
                                //direction
                                        JLabel lbDirection = new JLabel("Direction");
                                        pnlStatus.add(lbDirection);
                                        pnlStatus.add(new JLabel("" + df.format(lblDirection)));
                                pnlStatus.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 50));
                        top.add(pnlStatus);
                        pnlMain.add(top,c);
                        // Fill middle box 'Orderqueue' with information
                        middle.setPreferredSize(new Dimension(335, 305));
                        middle.setBorder(BorderFactory.createTitledBorder("ORDERQUEUE"));
                                middle.add(new orderQueue());
                        c.gridy = 1;
                        pnlMain.add(middle,c);
                        // Fill bottom box 'Orders' with information
                        bottom.setPreferredSize(new Dimension(335, 50));
                        bottom.setBorder(BorderFactory.createTitledBorder("ORDERS"));
                //Return the panel
                return pnlMain;
        }
        private void updateObjectInfo(){
        	//Get the latest vehicle information
                if(Connection.getMyVehicle().getName() != null){
                        lblName                 = Connection.getMyVehicle().getName();
                        lblType                 = Connection.getMyVehicle().getVehicleType().toString();
                        lblHealth               = Connection.getMyVehicle().getHealth();
                        lblFuel                 = Connection.getMyVehicle().getFuel();
                        lblPositionX    = Connection.getMyVehicle().getPosition().getX();
                        lblPositionY    = Connection.getMyVehicle().getPosition().getY();
                        lblSpeed                = Connection.getMyVehicle().getSpeed();
                        lblDirection    = Connection.getMyVehicle().getDirection();     
                }
        }
}